<template>
  <div>
    <div
      class="my-goods-item"
      v-for="item in list"
      :key="item.id"
    >
      <div class="left">
        <div class="custom-control custom-checkbox">
          <input
            type="checkbox"
            class="custom-control-input"
            v-model="item.goods_state"
            :id='item.id'
          >
          <label
            class="custom-control-label"
            :for="item.id"
          >
            <img :src="item.goods_img">
          </label>
        </div>
      </div>
      <div class="right">
        <div class="top">{{item.goods_name}}</div>
        <div class="bottom">
          <span class="price">¥ {{item.goods_price}}</span>
          <span>
            <div class="my-counter">
              <button
                type="button"
                class="btn btn-light"
                @click="uppr(item.id)"
              >-</button>
              <input
                type="number"
                class="form-control inp"
                v-model="item.goods_count"
                @input="inptr(item.id,$event)"
              >
              <button
                type="button"
                class="btn btn-light"
                @click="addr(item.id)"
              >+</button>
            </div>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState, mapMutations } from "vuex";
//导入局部组件必须在scrip里面导入,在App里面导入
export default {
  // 组件名称
  name: '',
  // 组件参数 接收来自父组件的数据
  props: {},
  // 接收局部注册的组件
  components: {},
  // 组件数据
  data () {
    return {

    }
  },
  methods: {
    ...mapActions(['getList']),
    ...mapMutations(['add', 'upp', 'inpt']),
    addr (id) {
      this.add(id)
    },
    uppr (id) {
      this.upp(id)
    },
    inptr (id, e) {
      console.log(e.target.value);
      this.inpt({ id: id, value: Number(e.target.value) })
    }
  },
  created () {
    this.getList()
  },
  computed: {
    ...mapState(['list']),
  }
}
</script>
<style lang="less" scoped>
.my-goods-item {
  display: flex;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  .left {
    img {
      width: 120px;
      height: 120px;
      margin-right: 8px;
      border-radius: 10px;
    }
    .custom-control-label::before,
    .custom-control-label::after {
      top: 50px;
    }
  }
  .right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top {
      font-size: 14px;
      font-weight: 700;
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      padding: 5px 0;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
    }
  }
}

.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>